package mybatis.service.impl;

import mybatis.dao.UserDao;
import mybatis.entity.User;
import mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;

/**
 * Author：汤小洋
 * Date：2022-11-23 16:03
 * Description：<描述>
 */
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    // @Transactional
    @Override
    public void register(User user) {
        userDao.insert(user);

        // int i = 5 / 0;

        // new SimpleDateFormat("yyyy-MM-dd").parse("23454345");
    }

    @Transactional(readOnly = true, timeout = 3000, isolation = Isolation.READ_COMMITTED)
    @Override
    public User login(String username, String password) {
        return userDao.selectByUsernameAndPassword(username, password);
    }
}
